package MallCoreStatistics

import (
	CoreSQL "gitee.com/fotomxq/weeekj_core/v5/core/sql"
	Router2SystemConfig "gitee.com/fotomxq/weeekj_core/v5/router2/system_config"
)

type ArgsCreateStatistics struct {
	//组织ID
	OrgID int64 `db:"org_id" json:"orgID"`
	//用户ID
	UserID int64 `db:"user_id" json:"userID"`
	//会员配置id
	MemberConfigID int64 `db:"member_config_id" json:"memberConfigID"`
	//商品ID
	GoodsID int64 `db:"goods_id" json:"goodsID"`
	//商品数量
	GoodsNum int64 `db:"goods_num" json:"goodsNum"`
	//订单id
	OrderID int64 `db:"order_id" json:"orderID"`
	//用户会员有效日期
	MemberValidDate string `db:"member_valid_date" json:"memberValidDate"`
	//订单等待id
	OrderWaitID int64 `db:"order_wait_id" json:"OrderWaitID"`
	//是否有效统计 0 无效 1 有效
	IsEffectiveStats int `db:"is_effective_stats" json:"isEffectiveStats"`
}

// CreateStatistics 创建会员商品统计
func CreateStatistics(args *ArgsCreateStatistics) (data FieldsStatistics, errCode string, err error) {
	//创建数据
	err = CoreSQL.CreateOneAndData(Router2SystemConfig.MainDB.DB, "mall_core_statistics",
		"INSERT INTO mall_core_statistics (org_id, user_id, member_config_id, goods_id, goods_num, order_id,member_valid_date,order_wait_id,is_effective_stats) VALUES (:org_id, :user_id, :member_config_id, :goods_id, :goods_num,:order_id, :member_valid_date, :order_wait_id, :is_effective_stats)", map[string]interface{}{
			"org_id":             args.OrgID,
			"user_id":            args.UserID,
			"member_config_id":   args.MemberConfigID,
			"goods_id":           args.GoodsID,
			"goods_num":          args.GoodsNum,
			"order_id":           args.OrderID,
			"member_valid_date":  args.MemberValidDate,
			"order_wait_id":      args.OrderWaitID,
			"is_effective_stats": args.IsEffectiveStats,
		}, &data)
	if err != nil {
		errCode = "insert"
		return
	}
	//反馈
	return
}
